#ifndef MDSPARSER_H
#define MDSPARSER_H

#include <map>
#include <vector>

class xMappingTree;
class xMappingNode;
class WOP_Entry;
class QString;
class QStringList;

#define MDS_VERSION "3.0"

class MDSParser
{
public:
	MDSParser();
	~MDSParser();
	xMappingTree* fromMDStoXMappingTree( QString, WOP_Entry* );
	xMappingTree* fromMDStoXMappingTree( std::string, WOP_Entry* );

private:
	std::map<std::string, xMappingNode *> _xnodes;
	std::map<std::string, int> _varablesTable;
	xMappingTree* _xmt;
	WOP_Entry* _en;

	void parseHeader( QStringList &tokens );
	void parseNodeDefinition( QString &mds);
	void parseNestedNode( QStringList & tokens, std::vector< std::string > & stdTokens );
	int addNode( std::string nodetype, std::string serialno, std::string parameter1, std::string parameter2, std::vector<std::string> &stdTokens );
	void parseTerminalNode( QString &mds );
	void addTerminalNode( std::string serialno );
	void parseLinkDefinition( QString &mds );
	void addLink( QStringList tokens, std::vector<std::string> stdTokens );
	void parseParameterized( QString &mds);
	void parseParameterizedBody( QStringList tokens );
	QStringList& getDefinitionBlock( QString );
	std::vector<std::string> toStdVector( QStringList& );
	void doForLoop(QString&, QString , int, int );
	void removeItemFromTokens(QStringList&, int);
	std::string generateSN();
	void replaceSymbolToValue(std::vector<std::string> &);
	void replaceSymbolToValue(QStringList &);
};

#endif // MDSPARSER_H
